package com.sxran.im.handler;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sxran.im.controller.ImController;
import com.sxran.im.dao.ImNotificationMapper;
import com.sxran.im.info.ImFriendInvite;
import com.sxran.im.info.ImNotification;
import com.sxran.im.service.FriendInviteService;
import com.sxran.im.service.NotificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class RefuseFriendApplicationCmdHandler extends AbstractCmdHandler<ImFriendInvite>{
    @Resource
    protected FriendInviteService friendInviteService;
    @Resource
    protected NotificationService notificationService;
    @Override
    public Object doBeanService(ImFriendInvite json) {
        // 修改申请
        updateState(json, -100);
        return json;
    }

    protected void updateState(ImFriendInvite json, int refuseState) {
        json.setState(refuseState);
        String curUserId = ImController.getCurUserId();
        json.setToUid(curUserId);
        friendInviteService.updateState(json);
        // 修改通知
        notificationService.updateFriendApplicationState(json.getFromUid(),curUserId, refuseState , json.getMessage());
    }

}
